package br.com.krauchenco.resourcemanager;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.Hashtable;
import java.util.Properties;
import java.util.logging.Logger;

import javax.imageio.ImageIO;

public class ResourceManager {
	/** Logger para mensagens */
	static final Logger logger = Logger.getLogger(ResourceManager.class
			.getName());
	private static ResourceManager instancia;
	private Hashtable<String, BufferedImage> cacheImage = new Hashtable<String, BufferedImage>();
	private Hashtable<String, InputStream> cacheStream = new Hashtable<String, InputStream>();
	private PropertiesWrapper properties = new PropertiesWrapper();
	private ResourceManager() {
		// nao implementado
	}
	
	public static synchronized ResourceManager getInstancia() {
		if (null == instancia) {
			instancia = new ResourceManager();
		}
		return instancia;
	}

	public BufferedImage getResourceAsImage(String string) throws IOException {
		BufferedImage retorno = cacheImage.get(string);
		if (null == retorno) {
			retorno = ImageIO.read(getClass().getResource(string));
			if (null != retorno) {
				cacheImage.put(string, retorno);
			} else {
				throw new IllegalArgumentException("Resource \"" + string + "\" not found!"); //$NON-NLS-1$ //$NON-NLS-2$
			}
		}
		return retorno;
	}

	public InputStream getResourceAsStream(String string) {
		InputStream retorno = cacheStream.get(string);
		if (null == retorno) {
			retorno = getClass().getResourceAsStream(string);
			if (null != retorno) {
				cacheStream.put(string, retorno);
			} else {
				throw new IllegalArgumentException("Resource \"" + string + "\" not found!"); //$NON-NLS-1$ //$NON-NLS-2$
			}
		}
		return retorno;
	}
	
	public String getMessage(String messageDefault, String propertie) {
		
	}
}
